package com.example.jpetstoreclient.controller;

import com.example.jpetstoreclient.common.CommonResponse;
import com.example.jpetstoreclient.domain.Animal;
import com.example.jpetstoreclient.service.AnimalService;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Validated
@CrossOrigin
@RestController
@RequestMapping("/animal")
public class AnimalController {
    @Autowired
    private AnimalService animalService;

    //  查找所有商品
    @GetMapping("/all")
    public CommonResponse<List<Animal>> showAll(){
        return animalService.getAllAnimals();
    }

    //  查找指定ID商品
    @GetMapping("/{id}")
    public CommonResponse<Animal> getAnimal(@PathVariable("id") @NotNull(message = "商品ID不能为空") int id){
        return animalService.getAnimalById(id);
    }

    //  查找指定编号商品
    @GetMapping("/find/name/{name}")
    public CommonResponse<List<Animal>> findByName(@PathVariable("name") @NotBlank(message = "商品编号不能为空") String name){
        return animalService.getAnimalsByName(name);
    }

    //  查找指定名称商品
    @GetMapping("/find/specific/{specific}")
    public CommonResponse<List<Animal>> findByGoodSpecific(@PathVariable("specific") @NotBlank(message = "商品名称不能为空") String good_specific){
        return animalService.getAnimalsByGood_Specific(good_specific);
    }

    //  查找指定种类商品
    @GetMapping("/find/type/{type}")
    public CommonResponse<List<Animal>> findByType(@PathVariable("type") @NotBlank(message = "商品种类不能为空") String type){
        return animalService.getAnimalsByType(type);
    }

    //  获取所有类别
    @GetMapping("/types")
    public CommonResponse<List<String>> getTypes(){
        return animalService.getAllTypes();
    }
}
